#!coding=utf-8
import hashlib

def verify_request(request,token):
    """
    判断接受到的消息是否来自于微信服务器
    request:  请求参数
    token: 密钥
    """
    signature = request.GET.get("signature", None)
    timestamp = request.GET.get("timestamp", None)
    nonce = request.GET.get("nonce", None)
#     echoStr = request.GET.get("echostr", None)
    tmpList = [token, timestamp, nonce]  
    tmpList.sort()  
    tmpstr = "%s%s%s" % tuple(tmpList)  
    tmpstr = hashlib.sha1(tmpstr).hexdigest()
    if tmpstr == signature: 
        return True
    return False

